package com.linzm.leetcode.primary.哈希表.有效的字母异位词;

import org.junit.Test;

/**
 * @Author zimingl
 * @Date 2022/10/6 22:20
 * @Description: TODO
 */
public class 哈希表383赎金信 {

    public boolean canConstruct(String ransomNote, String magazine) {
        int[] table = new int[26];

        for (int i = 0; i < magazine.length(); i ++){
            table[magazine.charAt(i) - 'a'] ++;
        }

        for (int i = 0; i < ransomNote.length(); i ++){
            table[ransomNote.charAt(i) - 'a'] --;
            if (table[ransomNote.charAt(i) - 'a'] < 0){
                return false;
            }
        }
        return true;
    }

    @Test
    public void test(){
       String ransomNote = "aa", magazine = "aab";
        System.out.println( canConstruct(ransomNote, magazine) );
    }
}
